package com.nengchuan.kbms.dfs.task;

import com.nengchuan.kbms.dfs.config.PdfConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * 功能描述: 清除缓存到目录中pdf文件
 *
 * @Param:
 * @Return:
 * @Author: luo_zm
 * @Date: 2020/4/13 11:20
 */
@Component
@Slf4j
public class ClearPdfFilesTask {
    @Autowired
    private PdfConfig pdfConfig;

    @Scheduled(cron = "0 0/30 * * * ? ")
    public void clearF() {
        log.info("清除缓存到服务器中的pdf任务_start");
        String pdfPath = pdfConfig.getPdfPath();
        File file = new File(pdfPath);
        if (file.exists() && file.isDirectory()) {
            //这里只获取配置目录下面的pdf文件,不循环递归,后续有需求在改变
            File[] files = file.listFiles();
            for (File file1 : files) {
                if (file1.isFile() && file1.getName().endsWith("pdf")) {
                    file1.delete();
                }
            }
        }
        log.info("清除缓存到服务器中的pdf任务_end");
    }

}
